//
//  SCHomeJFSCView.m
//  shangcheng
//
//  Created by Jie Jie on 2019/6/17.
//  Copyright © 2019 张艳江. All rights reserved.
//

#import "SCHomeJFSCView.h"
#import "SCHomeJFSCCell.h"

CGFloat const k_home_jfsc_lr_out_space = 9;
CGFloat const k_home_jfsc_lr_in_space = 12;

#define bg_view_w     kScreenW - k_home_jfsc_lr_out_space*2


static NSString *cellIdentifier = @"SCHomeJFSCCell";

@interface SCHomeJFSCView()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic , strong) UICollectionView *collection_view;


@end

@implementation SCHomeJFSCView

-(instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if(self){
        
        UIView *bg_view = [[UIView alloc] initWithFrame:CGRectMake(9, 0, bg_view_w, k_jfsc_view_h)];
        bg_view.layer.masksToBounds = YES;
        bg_view.layer.cornerRadius = 2;
        bg_view.backgroundColor = [UIColor whiteColor];
        [self addSubview:bg_view];
        
        [bg_view addSubview:self.collection_view];
    }
    return self;
}

#pragma mark 私有方法
-(UICollectionView *)collection_view{
    
    if (_collection_view == nil) {
        
        CGFloat layout_w = (bg_view_w- k_home_jfsc_lr_in_space * 4) / 3;
        CGFloat layout_h = (k_jfsc_view_h  - k_home_jfsc_lr_in_space * 2)/ 2;
        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(layout_w, layout_h);
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        layout.minimumLineSpacing = k_home_jfsc_lr_in_space;
        layout.minimumInteritemSpacing = k_home_jfsc_lr_in_space;
        _collection_view = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, bg_view_w, k_jfsc_view_h) collectionViewLayout:layout];
        _collection_view.backgroundColor = [UIColor whiteColor];
        _collection_view.showsHorizontalScrollIndicator = NO;
        _collection_view.showsVerticalScrollIndicator = NO;
        _collection_view.dataSource = self;
        _collection_view.delegate = self;
        
        [_collection_view registerClass:[SCHomeJFSCCell class] forCellWithReuseIdentifier:cellIdentifier];
        
    }
    
    return _collection_view;
    
}

#pragma mark 对外方法
-(void)setHome_jfsc_array:(NSMutableArray *)home_jfsc_array{
    
    _home_jfsc_array = home_jfsc_array;
    [self.collection_view reloadData];
    
}

#pragma mark - UICollectionViewDataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
//    return _home_jfsc_array.count;
     return 6;
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    SCHomeJFSCCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    
    
    return cell;
    
}



// 定义section的边距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    
    return UIEdgeInsetsMake(k_home_jfsc_lr_in_space, k_home_jfsc_lr_in_space, 0, k_home_jfsc_lr_in_space);
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
}


@end
